Skip to content

Conversation

@jessegrabowski
Copy link
Member

Description

This PR adds a variance function that returns the (symbolic) variance of a distribution. I added it because I thought it would be nice to have for the AutoGuide stuff; we can use the mean and variance of priors to initialize the parameters.

This is a 90%+ LLM PR. I went through and tried to clean things up. I mostly copied the patterns from mean.py.

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 98.23009% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.97%. Comparing base (5ff12c8) to head (9649395).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
pymc/distributions/moments/variances.py 98.21% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8084      +/-   ##
==========================================
+ Coverage   90.80%   90.97%   +0.16%     
==========================================
  Files         121      124       +3     
  Lines       19443    19714     +271     
==========================================
+ Hits        17656    17935     +279     
+ Misses       1787     1779       -8     
Files with missing lines Coverage Δ
pymc/distributions/moments/__init__.py 100.00% <100.00%> (ø)
pymc/distributions/moments/variances.py 98.21% <98.21%> (ø)

... and 12 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@lucianopaz lucianopaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. My only suggestion is that we move the maybe_resize utility from means and variances to utils.py, but I'll approve anyway and you can move it or not.

return _variance(rv.owner.op, rv, *rv.owner.inputs)


def maybe_resize(a: TensorVariable, size) -> TensorVariable:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this and the one in means should be moved to some common utility module?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants